package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.constant.Navigation;
import com.qire.common.support.base.EventController;
import com.qire.common.widget.adapter.auto.AutoVariable;
import com.qire.manhua.activity.RecommendMoreActivity;
import com.qire.manhua.databinding.ActivityRecommendMoreBinding;
import com.qire.manhua.databinding.LayoutRecommendMoreItmeBinding;
import com.qire.manhua.model.viewModel.impl.RecommendMoreViewModel;
import com.qire.manhua.model.viewModel.impl.RecommendMoreViewModel.RecommendMoreItemViewModel;
import com.scwang.smart.refresh.layout.api.RefreshLayout;

import androidx.annotation.NonNull;

public class RecommendMoreController extends EventController<RecommendMoreActivity> implements AutoVariable<LayoutRecommendMoreItmeBinding> {

    private RecommendMoreViewModel viewModel;

    public RecommendMoreController(@NonNull RecommendMoreActivity lifecycleOwner) {
        super(lifecycleOwner);
    }

    @Override
    protected void bindView() {
        ActivityRecommendMoreBinding viewDataBinder = owner.viewDataBinder();
        viewDataBinder.setRecommendMoreController(this);
    }

    @Override
    public void bindVariable(LayoutRecommendMoreItmeBinding viewBind) {
        viewBind.setRecommendMoreController(this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(RecommendMoreViewModel viewModel) {
        this.viewModel = viewModel;
    }

    /*************************************************************************************************************************/

    public void backBtnOnclick(View view){
        owner.onBackPressed();
    }

    public void refreshLayoutOnLoadMore(RefreshLayout refreshLayout) {
        viewModel.refreshMoreData();
    }
    public void refreshLayoutOnRefresh(RefreshLayout refreshLayout) {
        viewModel.loadMoreData();
    }

    public void moduleItemOnClick(View view) {
        RecommendMoreItemViewModel moduleItemEntity = (RecommendMoreItemViewModel) view.getTag();
        AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicReaderPage)
                .withData("comicBookEntity", moduleItemEntity.toComicBookEntity())
                .navigation();
    }

}
